Buttons are an essential part of web development, allowing users to interact with a webpage by submitting forms,
triggering JavaScript actions, or navigating to different pages. In HTML, the <button> element is
used to create buttons, and it comes with various types, attributes, and use cases.
The <button> Element
The <button> element is used to create clickable buttons. By default, it is rendered as a
rectangular clickable element.
*Types of Buttons in HTML*
The <button> element has a type attribute that defines its behavior. There are three main
types:
Submit Button (type="submit")
A submit button is used inside a form. When clicked, it submits the form data to the specified action URL.
Reset Button (type="reset")
A reset button clears all the form fields back to their default values.
Regular Button (type="button")
A regular button does nothing on its own but can be used with JavaScript to trigger actions.
Using <input> as a Button
In addition to <button>, you can also create buttons using the <input>
element.
Styling Buttons with CSS
By default, buttons have a basic style. You can customize them using CSS.
The button has a blue background, white text, and rounded corners.
When hovered, the background becomes darker blue.
Button Best Practices
Use type="button" when using JavaScript
Use button instead of input for better styling and flexibility
Add aria-label for accessibility when needed
Use CSS to improve button appearance
Summary Table
Submit Submits form data. <button type="submit">Submit</button>
Reset Clears form fields. <button type="reset">Reset</button>